
$(function () {
	$(".myDate").datepick();
	$("#newContract").click(function () {
	   if($("#contractTable >tbody >tr").length<4){
	   		$("#contractTable >tbody").append($("#contractTemple >tbody >tr").clone());
	   }
	});
	$("#deleteContract").click(function () {
		$("#contractTable >tbody >tr .checkBox:checked").each(function (index) {
			$(this).parent().parent().remove();
		});
	});
	
	$("#newComplete").click(function () {
	  if($("#mainCompleteTable >tbody >tr").length<2){
		  $("#mainCompleteTable >tbody").append($("#mainCompleteTemple >tbody >tr").clone());
	  }
	});
	$("#deleteComplete").click(function () {
		$("#mainCompleteTable >tbody >tr .checkBox:checked").each(function (index) {
			$(this).parent().parent().remove();
		});
	});
	$("#newComepeteBrand").click(function () {
	if($("#complete4sTable >tbody >tr").length<10){
			$("#complete4sTable >tbody").append($("#complete4sTemple >tbody >tr").clone());
	}
	});
	$("#deleteComepeteBrand").click(function () {
		$("#completeBrandTable >tbody >tr .checkBox:checked").each(function (index) {
			$(this).parent().parent().remove();
		});
	});
	$("#newTireType").click(function () {
	    if($("#tireTypeTable >tbody >tr").length<10){
	    	$("#tireTypeTable >tbody").append($("#tireTypeTemple >tbody >tr").clone());
	    }
	});
	$("#deleteTireType").click(function () {
		$("#tireTypeTable >tbody >tr .checkBox:checked").each(function (index) {
			$(this).parent().parent().remove();
		});
	});
	$("#submitForm").click(function () {
		$("#contractTable >tbody >tr").each(function (index) {
			$(this).find(".contractName").attr("name", $(this).find(".contractName").attr("name").replace(new RegExp("pContract", "g"), index));
			$(this).find(".contractPost").attr("name", $(this).find(".contractPost").attr("name").replace(new RegExp("pContract", "g"), index));
			$(this).find(".contractTel").attr("name", $(this).find(".contractTel").attr("name").replace(new RegExp("pContract", "g"), index));
			$(this).find(".contractFax").attr("name", $(this).find(".contractFax").attr("name").replace(new RegExp("pContract", "g"), index));
			$(this).find(".contractPhone").attr("name", $(this).find(".contractPhone").attr("name").replace(new RegExp("pContract", "g"), index));
			$(this).find(".contractEmail").attr("name", $(this).find(".contractEmail").attr("name").replace(new RegExp("pContract", "g"), index));
		});
		$("#complete4sTable >tbody >tr").each(function (index) {
			$(this).find(".completeBrand").attr("name", $(this).find(".completeBrand").attr("name").replace(new RegExp("pComplete4s", "g"), index));
			$(this).find(".sendType").attr("name", $(this).find(".sendType").attr("name").replace(new RegExp("pComplete4s", "g"), index));
			$(this).find(".redetailerPromotion").attr("name", $(this).find(".redetailerPromotion").attr("name").replace(new RegExp("pComplete4s", "g"), index));
			$(this).find(".temPromotion").attr("name", $(this).find(".temPromotion").attr("name").replace(new RegExp("pComplete4s", "g"), index));
			$(this).find(".train4s").attr("name", $(this).find(".train4s").attr("name").replace(new RegExp("pComplete4s", "g"), index));
			$(this).find(".stock").attr("name", $(this).find(".stock").attr("name").replace(new RegExp("pComplete4s", "g"), index));
		});
		
		$("#tireTypeTable >tbody >tr").each(function (index) {
			$(this).find(".carType").attr("name", $(this).find(".carType").attr("name").replace(new RegExp("pTireType", "g"), index));
			$(this).find(".figure").attr("name", $(this).find(".figure").attr("name").replace(new RegExp("pTireType", "g"), index));
		});
		
		$("#mainCompleteTable >tbody >tr").each(function (index) {
			$(this).find(".brand").attr("name", $(this).find(".brand").attr("name").replace(new RegExp("pMainComplete", "g"), index));
			$(this).find(".brandCount").attr("name", $(this).find(".brandCount").attr("name").replace(new RegExp("pMainComplete", "g"), index));
		});
		$("#mainForm")[0].submit();
	});
});

